package br.edu.unirn.dao;

import javax.faces.bean.ManagedBean;

import org.hibernate.Query;
import org.hibernate.Session;

import br.edu.unirn.dominio.Cliente;

@ManagedBean
public class ClienteDao extends GenericDAO<Cliente> {

	@Override
	public Class<Cliente> getClassType() {
		return Cliente.class;
	}
	
	public Cliente findClienteByEmailSenha(Cliente cliente) {
		String hql = "select c from Cliente c where email = :email and senha = :senha";
		
		Session session = (Session) getEm().getDelegate();
		
		Query q = session.createQuery(hql);
		
		q.setParameter("email", cliente.getEmail());
		q.setParameter("senha", cliente.getSenha());
		
		q.setMaxResults(1);
		
		return (Cliente) q.uniqueResult();
	}

}
